package com.community.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.community.dao.IBaseDao;
import com.community.entity.Postings;
import com.community.service.IPostingsService;

@Service
public class PostingsServiceImpl implements IPostingsService{
	
	@Autowired
	private IBaseDao<Postings> pdao;

	@Override
	public void addPostings(Postings p) {
		// TODO Auto-generated method stub
		pdao.save(p);
	}

	@Override
	public List<Postings> getPostingsList() {
		// TODO Auto-generated method stub
		return pdao.find("from Postings");
	}

	@Override
	public Postings getPostings(Long id) {
		// TODO Auto-generated method stub
		return pdao.get(Postings.class, id);
	}

	@Override
	public List<Postings> getPostingsListByUserId(Long userId) {
		// TODO Auto-generated method stub
		String jpql = "from Postings where userId = ?1";
		Map<String,Object> params = new HashMap<>();
		params.put("1", userId);
		List<Postings>  pList= pdao.find(jpql, params);
		return pList;
	}

	@Override
	public void delete(Postings p) {
		// TODO Auto-generated method stub
		pdao.delete(p);
	}

}
